package src.com.atguigu06.project.team.service;

import src.com.atguigu06.project.team.domain.*;
import src.com.atguigu06.project.team.domain.Architcet;
import static src.com.atguigu06.project.team.service.Data.*;

/**
 * ClassName: NameListEmployee
 * Package: src.com.atguigu06.project.team.service
 * Description:
 *
 * @Author BuTang
 * @Create 2023/5/5 23:13
 * @Version 1.0
 */
public class NameListService {
    private Employee[] employees;

    public Employee getEmployees(int id) throws TeamException{
        for (int i = 0; i < employees.length; i++) {
            if (id-1 == i) {
                return employees[i];
            }

        }
        throw new TeamException("该员工不存在");

    }
    public Employee[] getAllEmployees(){
        return employees;
    }

    /**
     * 把人员转换成所需要的类型
     */
    public NameListService() {
        employees = new Employee[EMPLOYEES.length];
        for (int i = 0; i < employees.length; i++) {
            int type = Integer.parseInt(EMPLOYEES[i][0]);
            int id = Integer.parseInt(EMPLOYEES[i][1]);
            String name = EMPLOYEES[i][2];
            int age = Integer.parseInt(EMPLOYEES[i][3]);
            int salary = Integer.parseInt(EMPLOYEES[i][4]);

            Equipment eq = null;
            double bonus;
            int stock;

            switch (type){
                case EMPLOYEE:
                    employees[i] = new Employee(id,name,age,salary);
                    break;
                case PROGRAMMER :
                    eq = createEquipment(i);
                    employees[i] = new Programmer(id,name,age,salary,eq);
                    break;
                case DESIGNER:
                    eq = createEquipment(i);
                    bonus = Double.parseDouble(EMPLOYEES[i][5]);
                    employees[i] = new Designer(id,name,age,salary,eq,bonus);
                    break;
                case ARCHITECT:
                    eq = createEquipment(i);
                    bonus = Double.parseDouble(EMPLOYEES[i][5]);
                    stock = Integer.parseInt(EMPLOYEES[i][6]);
                    employees[i] = new Architcet(id,name,age,salary,eq,bonus,stock);
                    break;

            }

    }
    }
    public Equipment createEquipment(int idex){
            int type = Integer.parseInt(EQIPMENTS[idex][0]);
            switch (type){
                case PC :
                    return new Pc(EQIPMENTS[idex][1],EQIPMENTS[idex][2]);
                case NOTEBOOK:
                    int price = Integer.parseInt(EQIPMENTS[idex][2]);
                    return new NoteBook(EQIPMENTS[idex][1],price);
                case PRINTER:
                    return new Printer(EQIPMENTS[idex][1],EQIPMENTS[idex][2]);
            }
            return null;
        }

    }


